import http from '../../utils/http'

/**
 * @description 用户咨询相关API接口
 */

/**
 * 获取医生列表
 * @param {number} page - 页码
 * @param {number} limit - 每页数量
 * @param {string} keyword - 搜索关键词
 * @param {string} department - 科室筛选
 * @returns {Promise} 医生列表
 */
export const reqDoctorList = (page = 1, limit = 10, keyword = '', department = '') => {
  return http.get('/advice/doctors', { page, limit, keyword, department })
}

/**
 * 获取医生详情
 * @param {number} doctorId - 医生ID
 * @returns {Promise} 医生详情
 */
export const reqDoctorDetail = (doctorId) => {
  return http.get(`/advice/doctors/${doctorId}`)
}

/**
 * 发起咨询请求
 * @param {Object} consultationData - 咨询数据
 * @returns {Promise} 咨询结果
 */
export const reqStartConsultation = (consultationData) => {
  return http.post('/advice/consultations', consultationData)
}

/**
 * 获取用户咨询列表
 * @param {number} page - 页码
 * @param {number} limit - 每页数量
 * @param {string} status - 状态筛选
 * @returns {Promise} 咨询列表
 */
export const reqUserConsultations = (page = 1, limit = 10, status = '') => {
  return http.get('/advice/consultations', { page, limit, status })
}

/**
 * 获取咨询详情
 * @param {number} consultationId - 咨询ID
 * @returns {Promise} 咨询详情
 */
export const reqConsultationDetail = (consultationId) => {
  return http.get(`/advice/consultations/${consultationId}`)
}

/**
 * 获取聊天记录
 * @param {number} consultationId - 咨询ID
 * @param {number} page - 页码
 * @param {number} limit - 每页数量
 * @returns {Promise} 聊天记录
 */
export const reqChatHistory = (consultationId, page = 1, limit = 50) => {
  return http.get(`/advice/consultations/${consultationId}/messages`, { page, limit })
}

/**
 * 发送消息
 * @param {number} consultationId - 咨询ID
 * @param {string} content - 消息内容
 * @param {string} type - 消息类型 (text/image/file)
 * @returns {Promise} 发送结果
 */
export const reqSendMessage = (consultationId, content, type = 'text') => {
  return http.post(`/advice/consultations/${consultationId}/messages`, {
    content,
    type
  })
}

/**
 * 标记消息为已读
 * @param {number} consultationId - 咨询ID
 * @returns {Promise} 标记结果
 */
export const reqMarkMessagesRead = (consultationId) => {
  return http.post(`/advice/consultations/${consultationId}/read`)
}

/**
 * 结束咨询
 * @param {number} consultationId - 咨询ID
 * @returns {Promise} 结束结果
 */
export const reqEndConsultation = (consultationId) => {
  return http.post(`/advice/consultations/${consultationId}/end`)
}

/**
 * 评价咨询
 * @param {number} consultationId - 咨询ID
 * @param {Object} ratingData - 评价数据
 * @returns {Promise} 评价结果
 */
export const reqRateConsultation = (consultationId, ratingData) => {
  return http.post(`/advice/consultations/${consultationId}/rating`, ratingData)
}

/**
 * 获取咨询历史
 * @param {number} page - 页码
 * @param {number} limit - 每页数量
 * @returns {Promise} 咨询历史
 */
export const reqConsultationHistory = (page = 1, limit = 10) => {
  return http.get('/advice/history', { page, limit })
}

/**
 * 取消咨询
 * @param {number} consultationId - 咨询ID
 * @returns {Promise} 取消结果
 */
export const reqCancelConsultation = (consultationId) => {
  return http.post(`/advice/consultations/${consultationId}/cancel`)
}

/**
 * 上传咨询附件
 * @param {string} filePath - 文件路径
 * @param {string} type - 文件类型
 * @returns {Promise} 上传结果
 */
export const reqUploadAttachment = (filePath, type = 'image') => {
  return http.upload('/advice/upload', filePath, { type })
}

/**
 * 获取医生排班信息
 * @param {number} doctorId - 医生ID
 * @param {string} date - 日期
 * @returns {Promise} 排班信息
 */
export const reqDoctorSchedule = (doctorId, date) => {
  return http.get(`/advice/doctors/${doctorId}/schedule`, { date })
}

/**
 * 预约咨询
 * @param {Object} appointmentData - 预约数据
 * @returns {Promise} 预约结果
 */
export const reqBookConsultation = (appointmentData) => {
  return http.post('/advice/appointments', appointmentData)
}

/**
 * 获取用户咨询统计
 * @returns {Promise} 统计数据
 */
export const reqUserConsultationStats = () => {
  return http.get('/advice/stats')
}

/**
 * 举报医生
 * @param {number} doctorId - 医生ID
 * @param {Object} reportData - 举报数据
 * @returns {Promise} 举报结果
 */
export const reqReportDoctor = (doctorId, reportData) => {
  return http.post(`/advice/doctors/${doctorId}/report`, reportData)
}

/**
 * 获取咨询费用
 * @param {number} doctorId - 医生ID
 * @param {string} consultationType - 咨询类型
 * @returns {Promise} 费用信息
 */
export const reqConsultationFee = (doctorId, consultationType = 'text') => {
  return http.get(`/advice/doctors/${doctorId}/fee`, { consultationType })
}

/**
 * 支付咨询费用
 * @param {number} consultationId - 咨询ID
 * @param {Object} paymentData - 支付数据
 * @returns {Promise} 支付结果
 */
export const reqPayConsultation = (consultationId, paymentData) => {
  return http.post(`/advice/consultations/${consultationId}/pay`, paymentData)
}
